﻿using DevExpress.XtraEditors;
using DXApplicationTangche.UC.圣同润.merchant;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 广州爱特安为科技.UC.圣同润.客服.售后
{
    public partial class Form售后单一览 : DevExpress.XtraEditors.XtraForm
    {
        private List<ViewRefundOrderDTO> viewRefundOrderDTOs = new List<ViewRefundOrderDTO>();
        private String type;
        public Form售后单一览()
        {
            InitializeComponent();
        }

        private void refreshData()
        {
            if ("退货退款".Equals(this.type))
            {
                this.gridColumnreturn_express_order_no.Visible = true;
                this.gridColumnreturn_express_order_no.VisibleIndex = 15;
                this.gridColumnsend_back_status_desc.Visible = true;
                this.gridColumnsend_back_status_desc.VisibleIndex = 16;
                this.gridColumnisContainCredential.Visible = true;
                this.gridColumnisContainCredential.VisibleIndex = 17;
                this.gridColumnprocessing_scheme.Visible = true;
                this.gridColumnprocessing_scheme.VisibleIndex = 18;
            }
            else
            {
                this.gridColumnreturn_express_order_no.Visible = false;
                this.gridColumnsend_back_status_desc.Visible = false;
                this.gridColumnisContainCredential.Visible = false;
                this.gridColumnprocessing_scheme.Visible = false;
            }
            this.viewRefundOrderDTOs = MerchantService.getRefundOrderByType(this.type);
            this.gridControl售后单一览.DataSource = this.viewRefundOrderDTOs;
            this.gridView售后单一览.RefreshData();
        }

        private void comboBox售后类型_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.type = this.comboBox售后类型.Text.Trim();
            this.refreshData();
        }

        private void 订单详情ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                String id = this.gridView售后单一览.GetRowCellValue(this.gridView售后单一览.FocusedRowHandle, "id").ToString();
                foreach (ViewRefundOrderDTO item in this.viewRefundOrderDTOs)
                {
                    if (id.Equals(item.id.ToString()))
                    {
                        new Form售后订单详情(item).ShowDialog();
                        break;
                    }
                }
            }
            catch { }
        }

        private void 二次审核详情ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if ("退货退款".Equals(this.type))
                {
                    String order_sn = this.gridView售后单一览.GetRowCellValue(this.gridView售后单一览.FocusedRowHandle, "order_sn").ToString();
                    String product_id = this.gridView售后单一览.GetRowCellValue(this.gridView售后单一览.FocusedRowHandle, "product_id").ToString();
                    foreach (ViewRefundOrderDTO item in this.viewRefundOrderDTOs)
                    {
                        if (order_sn.Equals(item.order_sn))
                        {

                            new Form售后二次审核详情(
                                item.order_sn,
                                item.product_id
                                )
                                .ShowDialog();
                            break;
                        }
                    }
                }
            }
            catch { }
        }

        private void simpleButton导出Excel_Click(object sender, EventArgs e)
        {
            if (this.gridView售后单一览.DataRowCount <= 0)
            {
                return;
            }
            SaveFileDialog fileDialog = new SaveFileDialog();
            fileDialog.Title = "导出Excel";
            fileDialog.Filter = "Excel文件(*.xls)|*.xls";
            DialogResult dialogResult = fileDialog.ShowDialog(this);
            if (dialogResult == DialogResult.OK)
            {
                DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions();
                this.gridView售后单一览.ExportToXls(fileDialog.FileName);
                DevExpress.XtraEditors.XtraMessageBox.Show("保存成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
    }
}